#include "stdafx.h"
#include "Mainform.h"
 
using namespace OgreUnified;

Mainform::Mainform(void)
{
	SplashScreenForm^ splash = gcnew SplashScreenForm();
	splash->Show();

	InitializeComponent();
	

	Ogre::LogManager* logman = new Ogre::LogManager();
	logman->createLog("DefaultLog.txt",true);
	gcnew ConsoleForm();

	mOgreInterface = new OgreInterface();

	if(!mOgreInterface->RestoreConfig())
	{
		EditorOptionsForm^ options = gcnew EditorOptionsForm();
		if(options->ShowDialog()== System::Windows::Forms::DialogResult::OK)
			mOgreInterface->Initialize();
	}
	else 
		mOgreInterface->Initialize();

	if(mOgreInterface->isInitialized())
	{
		/*forms*/
		gcnew GameViewForm();
		gcnew HierarchyForm();
		gcnew InspectorForm();
		gcnew ProjectResourcesForm();
		gcnew ProjectSetupForm();
		
		/*--tools & managers--*/
		gcnew SceneViewManager();


		if(System::IO::File::Exists("Layout.xml"))
		{
			mDockPanel->LoadFromXml("Layout.xml", gcnew WeifenLuo::WinFormsUI::Docking::DeserializeDockContent(this, &Mainform::LoadLayoutCallback));
		}
		else
		{
			ConsoleForm::Instance->Show(mDockPanel);
			HierarchyForm::Instance->Show(mDockPanel);
			InspectorForm::Instance->Show(mDockPanel);
			ProjectResourcesForm::Instance->Show(mDockPanel);
		}
	}
	else
	{
		System::Windows::Forms::MessageBox::Show("Could not initialize Ogre");
	}

	Instance = this;
	delete splash;

	Shown += gcnew EventHandler(this, &Mainform::OnShown);

}

void Mainform::OnShown(Object^ o, System::EventArgs^ e)
{
	SceneViewManager::Instance->StartRendering(  );
	
}

Mainform::~Mainform()
{
	SceneViewManager::Instance->StopRendering();
	if(mOgreInterface)
	{
		delete mOgreInterface;
	}

	ConsoleForm::Instance->removeListener();

	CloseAllDocuments();

	if (components)
	{
		delete components;
	}
}

IDockContent^ Mainform::LoadLayoutCallback(System::String^ formName)
{
	if(formName == "OgreUnified.ConsoleForm")
		return ConsoleForm::Instance;
	if(formName == "OgreUnified.HierarchyForm")
		return HierarchyForm::Instance;
	if(formName == "OgreUnified.ProjectResourcesForm")
		return ProjectResourcesForm::Instance;
	if(formName == "OgreUnified.InspectorForm")
		return InspectorForm::Instance;
	if(formName == "OgreUnified.SceneViewForm")
		return SceneViewManager::Instance->addSceneView();
	
	return nullptr;
}

void Mainform::InitializeComponent(void)
{
	WeifenLuo::WinFormsUI::Docking::DockPanelSkin^  dockPanelSkin1 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPanelSkin());
	WeifenLuo::WinFormsUI::Docking::AutoHideStripSkin^  autoHideStripSkin1 = (gcnew WeifenLuo::WinFormsUI::Docking::AutoHideStripSkin());
	WeifenLuo::WinFormsUI::Docking::DockPanelGradient^  dockPanelGradient1 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPanelGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient1 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	WeifenLuo::WinFormsUI::Docking::DockPaneStripSkin^  dockPaneStripSkin1 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPaneStripSkin());
	WeifenLuo::WinFormsUI::Docking::DockPaneStripGradient^  dockPaneStripGradient1 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPaneStripGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient2 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	WeifenLuo::WinFormsUI::Docking::DockPanelGradient^  dockPanelGradient2 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPanelGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient3 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	WeifenLuo::WinFormsUI::Docking::DockPaneStripToolWindowGradient^  dockPaneStripToolWindowGradient1 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPaneStripToolWindowGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient4 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient5 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	WeifenLuo::WinFormsUI::Docking::DockPanelGradient^  dockPanelGradient3 = (gcnew WeifenLuo::WinFormsUI::Docking::DockPanelGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient6 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	WeifenLuo::WinFormsUI::Docking::TabGradient^  tabGradient7 = (gcnew WeifenLuo::WinFormsUI::Docking::TabGradient());
	System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Mainform::typeid));
	this->mDockPanel = (gcnew WeifenLuo::WinFormsUI::Docking::DockPanel());
	this->mMenuStrip = (gcnew System::Windows::Forms::MenuStrip());
	this->mToolStripMenuItemFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemNewScene = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemOpenScene = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripFileSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
	this->mToolStripMenuItemSaveScene = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemSaveSceneAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripFileSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
	this->mToolStripMenuItemNewProject = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemOpenProject = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemSaveProject = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripFileSeparator3 = (gcnew System::Windows::Forms::ToolStripSeparator());
	this->mToolStripMenuItemBuildSettings = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemBuildRun = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripFileSeparator4 = (gcnew System::Windows::Forms::ToolStripSeparator());
	this->mToolStripMenuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemEdit = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemAssets = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemGameObjects = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemComponent = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemWindows = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemLayout = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemLoad = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemConsole = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemGameView = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemSceneView = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemInspector = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemProject = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemHierarchy = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStripMenuItemHelp = (gcnew System::Windows::Forms::ToolStripMenuItem());
	this->mToolStrip = (gcnew System::Windows::Forms::ToolStrip());
	this->mToolStriputtonNew = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripButtonOpen = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripButtonSave = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripButtonPrint = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripSeparator = (gcnew System::Windows::Forms::ToolStripSeparator());
	this->mToolStripButtonCut = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripButtonCopy = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripButtonPaste = (gcnew System::Windows::Forms::ToolStripButton());
	this->mmToolStripFileSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
	this->mToolStripButtonHelp = (gcnew System::Windows::Forms::ToolStripButton());
	this->mToolStripContainer = (gcnew System::Windows::Forms::ToolStripContainer());
	this->mStatusStrip = (gcnew System::Windows::Forms::StatusStrip());
	this->mToolStripStatusLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
	this->mMenuStrip->SuspendLayout();
	this->mToolStrip->SuspendLayout();
	this->mToolStripContainer->BottomToolStripPanel->SuspendLayout();
	this->mToolStripContainer->ContentPanel->SuspendLayout();
	this->mToolStripContainer->TopToolStripPanel->SuspendLayout();
	this->mToolStripContainer->SuspendLayout();
	this->mStatusStrip->SuspendLayout();
	this->SuspendLayout();
	// 
	// mDockPanel
	// 
	this->mDockPanel->ActiveAutoHideContent = nullptr;
	this->mDockPanel->BackColor = System::Drawing::SystemColors::ActiveCaption;
	this->mDockPanel->Dock = System::Windows::Forms::DockStyle::Fill;
	this->mDockPanel->DockBackColor = System::Drawing::SystemColors::ActiveCaption;
	this->mDockPanel->DocumentStyle = WeifenLuo::WinFormsUI::Docking::DocumentStyle::DockingWindow;
	this->mDockPanel->Location = System::Drawing::Point(0, 0);
	this->mDockPanel->Name = L"mDockPanel";
	this->mDockPanel->Size = System::Drawing::Size(784, 491);
	dockPanelGradient1->EndColor = System::Drawing::SystemColors::ControlLight;
	dockPanelGradient1->StartColor = System::Drawing::SystemColors::ControlLight;
	autoHideStripSkin1->DockStripGradient = dockPanelGradient1;
	tabGradient1->EndColor = System::Drawing::SystemColors::Control;
	tabGradient1->StartColor = System::Drawing::SystemColors::Control;
	tabGradient1->TextColor = System::Drawing::SystemColors::ControlDarkDark;
	autoHideStripSkin1->TabGradient = tabGradient1;
	dockPanelSkin1->AutoHideStripSkin = autoHideStripSkin1;
	tabGradient2->EndColor = System::Drawing::SystemColors::ControlLightLight;
	tabGradient2->StartColor = System::Drawing::SystemColors::ControlLightLight;
	tabGradient2->TextColor = System::Drawing::SystemColors::ControlText;
	dockPaneStripGradient1->ActiveTabGradient = tabGradient2;
	dockPanelGradient2->EndColor = System::Drawing::SystemColors::Control;
	dockPanelGradient2->StartColor = System::Drawing::SystemColors::Control;
	dockPaneStripGradient1->DockStripGradient = dockPanelGradient2;
	tabGradient3->EndColor = System::Drawing::SystemColors::ControlLight;
	tabGradient3->StartColor = System::Drawing::SystemColors::ControlLight;
	tabGradient3->TextColor = System::Drawing::SystemColors::ControlText;
	dockPaneStripGradient1->InactiveTabGradient = tabGradient3;
	dockPaneStripSkin1->DocumentGradient = dockPaneStripGradient1;
	tabGradient4->EndColor = System::Drawing::SystemColors::ActiveCaption;
	tabGradient4->LinearGradientMode = System::Drawing::Drawing2D::LinearGradientMode::Vertical;
	tabGradient4->StartColor = System::Drawing::SystemColors::GradientActiveCaption;
	tabGradient4->TextColor = System::Drawing::SystemColors::ActiveCaptionText;
	dockPaneStripToolWindowGradient1->ActiveCaptionGradient = tabGradient4;
	tabGradient5->EndColor = System::Drawing::SystemColors::Control;
	tabGradient5->StartColor = System::Drawing::SystemColors::Control;
	tabGradient5->TextColor = System::Drawing::SystemColors::ControlText;
	dockPaneStripToolWindowGradient1->ActiveTabGradient = tabGradient5;
	dockPanelGradient3->EndColor = System::Drawing::SystemColors::ControlLight;
	dockPanelGradient3->StartColor = System::Drawing::SystemColors::ControlLight;
	dockPaneStripToolWindowGradient1->DockStripGradient = dockPanelGradient3;
	tabGradient6->EndColor = System::Drawing::SystemColors::GradientInactiveCaption;
	tabGradient6->LinearGradientMode = System::Drawing::Drawing2D::LinearGradientMode::Vertical;
	tabGradient6->StartColor = System::Drawing::SystemColors::GradientInactiveCaption;
	tabGradient6->TextColor = System::Drawing::SystemColors::ControlText;
	dockPaneStripToolWindowGradient1->InactiveCaptionGradient = tabGradient6;
	tabGradient7->EndColor = System::Drawing::Color::Transparent;
	tabGradient7->StartColor = System::Drawing::Color::Transparent;
	tabGradient7->TextColor = System::Drawing::SystemColors::ControlDarkDark;
	dockPaneStripToolWindowGradient1->InactiveTabGradient = tabGradient7;
	dockPaneStripSkin1->ToolWindowGradient = dockPaneStripToolWindowGradient1;
	dockPanelSkin1->DockPaneStripSkin = dockPaneStripSkin1;
	this->mDockPanel->Skin = dockPanelSkin1;
	this->mDockPanel->TabIndex = 0;
	// 
	// mMenuStrip
	// 
	this->mMenuStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(7) {this->mToolStripMenuItemFile, 
		this->mToolStripMenuItemEdit, this->mToolStripMenuItemAssets, this->mToolStripMenuItemGameObjects, this->mToolStripMenuItemComponent, 
		this->mToolStripMenuItemWindows, this->mToolStripMenuItemHelp});
	this->mMenuStrip->Location = System::Drawing::Point(0, 0);
	this->mMenuStrip->Name = L"mMenuStrip";
	this->mMenuStrip->Size = System::Drawing::Size(784, 24);
	this->mMenuStrip->TabIndex = 1;
	this->mMenuStrip->Text = L"menuStrip1";
	// 
	// mToolStripMenuItemFile
	// 
	this->mToolStripMenuItemFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(14) {this->mToolStripMenuItemNewScene, 
		this->mToolStripMenuItemOpenScene, this->mToolStripFileSeparator1, this->mToolStripMenuItemSaveScene, this->mToolStripMenuItemSaveSceneAs, 
		this->mToolStripFileSeparator2, this->mToolStripMenuItemNewProject, this->mToolStripMenuItemOpenProject, this->mToolStripMenuItemSaveProject, 
		this->mToolStripFileSeparator3, this->mToolStripMenuItemBuildSettings, this->mToolStripMenuItemBuildRun, this->mToolStripFileSeparator4, 
		this->mToolStripMenuItemExit});
	this->mToolStripMenuItemFile->Name = L"mToolStripMenuItemFile";
	this->mToolStripMenuItemFile->Size = System::Drawing::Size(37, 20);
	this->mToolStripMenuItemFile->Text = L"File";
	// 
	// mToolStripMenuItemNewScene
	// 
	this->mToolStripMenuItemNewScene->Name = L"mToolStripMenuItemNewScene";
	this->mToolStripMenuItemNewScene->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemNewScene->Text = L"New Scene";
	this->mToolStripMenuItemNewScene->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemNewScene_Click);
	// 
	// mToolStripMenuItemOpenScene
	// 
	this->mToolStripMenuItemOpenScene->Name = L"mToolStripMenuItemOpenScene";
	this->mToolStripMenuItemOpenScene->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemOpenScene->Text = L"Open Scene";
	this->mToolStripMenuItemOpenScene->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemOpenScene_Click);
	// 
	// mToolStripFileSeparator1
	// 
	this->mToolStripFileSeparator1->Name = L"mToolStripFileSeparator1";
	this->mToolStripFileSeparator1->Size = System::Drawing::Size(154, 6);
	// 
	// mToolStripMenuItemSaveScene
	// 
	this->mToolStripMenuItemSaveScene->Name = L"mToolStripMenuItemSaveScene";
	this->mToolStripMenuItemSaveScene->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemSaveScene->Text = L"Save Scene";
	this->mToolStripMenuItemSaveScene->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemSaveScene_Click);
	// 
	// mToolStripMenuItemSaveSceneAs
	// 
	this->mToolStripMenuItemSaveSceneAs->Name = L"mToolStripMenuItemSaveSceneAs";
	this->mToolStripMenuItemSaveSceneAs->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemSaveSceneAs->Text = L"Save Scene As...";
	this->mToolStripMenuItemSaveSceneAs->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemSaveSceneAs_Click);
	// 
	// mToolStripFileSeparator2
	// 
	this->mToolStripFileSeparator2->Name = L"mToolStripFileSeparator2";
	this->mToolStripFileSeparator2->Size = System::Drawing::Size(154, 6);
	// 
	// mToolStripMenuItemNewProject
	// 
	this->mToolStripMenuItemNewProject->Name = L"mToolStripMenuItemNewProject";
	this->mToolStripMenuItemNewProject->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemNewProject->Text = L"New Project...";
	this->mToolStripMenuItemNewProject->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemNewProject_Click);
	// 
	// mToolStripMenuItemOpenProject
	// 
	this->mToolStripMenuItemOpenProject->Name = L"mToolStripMenuItemOpenProject";
	this->mToolStripMenuItemOpenProject->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemOpenProject->Text = L"Open Project...";
	this->mToolStripMenuItemOpenProject->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemOpenProject_Click);
	// 
	// mToolStripMenuItemSaveProject
	// 
	this->mToolStripMenuItemSaveProject->Name = L"mToolStripMenuItemSaveProject";
	this->mToolStripMenuItemSaveProject->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemSaveProject->Text = L"Save Project";
	this->mToolStripMenuItemSaveProject->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemSaveProject_Click);
	// 
	// mToolStripFileSeparator3
	// 
	this->mToolStripFileSeparator3->Name = L"mToolStripFileSeparator3";
	this->mToolStripFileSeparator3->Size = System::Drawing::Size(154, 6);
	// 
	// mToolStripMenuItemBuildSettings
	// 
	this->mToolStripMenuItemBuildSettings->Name = L"mToolStripMenuItemBuildSettings";
	this->mToolStripMenuItemBuildSettings->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemBuildSettings->Text = L"Build Settings...";
	this->mToolStripMenuItemBuildSettings->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemBuildSettings_Click);
	// 
	// mToolStripMenuItemBuildRun
	// 
	this->mToolStripMenuItemBuildRun->Name = L"mToolStripMenuItemBuildRun";
	this->mToolStripMenuItemBuildRun->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemBuildRun->Text = L"Build & Run";
	this->mToolStripMenuItemBuildRun->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemBuildRun_Click);
	// 
	// mToolStripFileSeparator4
	// 
	this->mToolStripFileSeparator4->Name = L"mToolStripFileSeparator4";
	this->mToolStripFileSeparator4->Size = System::Drawing::Size(154, 6);
	// 
	// mToolStripMenuItemExit
	// 
	this->mToolStripMenuItemExit->Name = L"mToolStripMenuItemExit";
	this->mToolStripMenuItemExit->Size = System::Drawing::Size(157, 22);
	this->mToolStripMenuItemExit->Text = L"Exit";
	this->mToolStripMenuItemExit->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemExit_Click);
	// 
	// mToolStripMenuItemEdit
	// 
	this->mToolStripMenuItemEdit->Name = L"mToolStripMenuItemEdit";
	this->mToolStripMenuItemEdit->Size = System::Drawing::Size(39, 20);
	this->mToolStripMenuItemEdit->Text = L"Edit";
	// 
	// mToolStripMenuItemAssets
	// 
	this->mToolStripMenuItemAssets->Name = L"mToolStripMenuItemAssets";
	this->mToolStripMenuItemAssets->Size = System::Drawing::Size(52, 20);
	this->mToolStripMenuItemAssets->Text = L"Assets";
	// 
	// mToolStripMenuItemGameObjects
	// 
	this->mToolStripMenuItemGameObjects->Name = L"mToolStripMenuItemGameObjects";
	this->mToolStripMenuItemGameObjects->Size = System::Drawing::Size(85, 20);
	this->mToolStripMenuItemGameObjects->Text = L"GameObject";
	// 
	// mToolStripMenuItemComponent
	// 
	this->mToolStripMenuItemComponent->Name = L"mToolStripMenuItemComponent";
	this->mToolStripMenuItemComponent->Size = System::Drawing::Size(83, 20);
	this->mToolStripMenuItemComponent->Text = L"Component";
	// 
	// mToolStripMenuItemWindows
	// 
	this->mToolStripMenuItemWindows->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(7) {this->mToolStripMenuItemLayout, 
		this->mToolStripMenuItemConsole, this->mToolStripMenuItemGameView, this->mToolStripMenuItemSceneView, this->mToolStripMenuItemInspector, 
		this->mToolStripMenuItemProject, this->mToolStripMenuItemHierarchy});
	this->mToolStripMenuItemWindows->Name = L"mToolStripMenuItemWindows";
	this->mToolStripMenuItemWindows->Size = System::Drawing::Size(68, 20);
	this->mToolStripMenuItemWindows->Text = L"Windows";
	// 
	// mToolStripMenuItemLayout
	// 
	this->mToolStripMenuItemLayout->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->mToolStripMenuItemSave, 
		this->mToolStripMenuItemLoad});
	this->mToolStripMenuItemLayout->Name = L"mToolStripMenuItemLayout";
	this->mToolStripMenuItemLayout->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemLayout->Text = L"Layout";
	// 
	// mToolStripMenuItemSave
	// 
	this->mToolStripMenuItemSave->Name = L"mToolStripMenuItemSave";
	this->mToolStripMenuItemSave->Size = System::Drawing::Size(100, 22);
	this->mToolStripMenuItemSave->Text = L"Save";
	this->mToolStripMenuItemSave->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemSave_Click);
	// 
	// mToolStripMenuItemLoad
	// 
	this->mToolStripMenuItemLoad->Name = L"mToolStripMenuItemLoad";
	this->mToolStripMenuItemLoad->Size = System::Drawing::Size(100, 22);
	this->mToolStripMenuItemLoad->Text = L"Load";
	this->mToolStripMenuItemLoad->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemLoad_Click);
	// 
	// mToolStripMenuItemConsole
	// 
	this->mToolStripMenuItemConsole->Name = L"mToolStripMenuItemConsole";
	this->mToolStripMenuItemConsole->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemConsole->Text = L"Console";
	this->mToolStripMenuItemConsole->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemConsole_Click);
	// 
	// mToolStripMenuItemGameView
	// 
	this->mToolStripMenuItemGameView->Name = L"mToolStripMenuItemGameView";
	this->mToolStripMenuItemGameView->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemGameView->Text = L"GameView";
	this->mToolStripMenuItemGameView->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemGameView_Click);
	// 
	// mToolStripMenuItemSceneView
	// 
	this->mToolStripMenuItemSceneView->Name = L"mToolStripMenuItemSceneView";
	this->mToolStripMenuItemSceneView->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemSceneView->Text = L"SceneView";
	this->mToolStripMenuItemSceneView->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemSceneView_Click);
	// 
	// mToolStripMenuItemInspector
	// 
	this->mToolStripMenuItemInspector->Name = L"mToolStripMenuItemInspector";
	this->mToolStripMenuItemInspector->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemInspector->Text = L"Inspector";
	this->mToolStripMenuItemInspector->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemInspector_Click);
	// 
	// mToolStripMenuItemProject
	// 
	this->mToolStripMenuItemProject->Name = L"mToolStripMenuItemProject";
	this->mToolStripMenuItemProject->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemProject->Text = L"Project";
	this->mToolStripMenuItemProject->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemProject_Click);
	// 
	// mToolStripMenuItemHierarchy
	// 
	this->mToolStripMenuItemHierarchy->Name = L"mToolStripMenuItemHierarchy";
	this->mToolStripMenuItemHierarchy->Size = System::Drawing::Size(130, 22);
	this->mToolStripMenuItemHierarchy->Text = L"Hierarchy";
	this->mToolStripMenuItemHierarchy->Click += gcnew System::EventHandler(this, &Mainform::mToolStripMenuItemHierarchy_Click);
	// 
	// mToolStripMenuItemHelp
	// 
	this->mToolStripMenuItemHelp->Name = L"mToolStripMenuItemHelp";
	this->mToolStripMenuItemHelp->Size = System::Drawing::Size(44, 20);
	this->mToolStripMenuItemHelp->Text = L"Help";
	// 
	// mToolStrip
	// 
	this->mToolStrip->Dock = System::Windows::Forms::DockStyle::None;
	this->mToolStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(10) {this->mToolStriputtonNew, 
		this->mToolStripButtonOpen, this->mToolStripButtonSave, this->mToolStripButtonPrint, this->mToolStripSeparator, this->mToolStripButtonCut, 
		this->mToolStripButtonCopy, this->mToolStripButtonPaste, this->mmToolStripFileSeparator2, this->mToolStripButtonHelp});
	this->mToolStrip->Location = System::Drawing::Point(3, 0);
	this->mToolStrip->Name = L"mToolStrip";
	this->mToolStrip->Size = System::Drawing::Size(208, 25);
	this->mToolStrip->TabIndex = 2;
	this->mToolStrip->Text = L"toolStrip1";
	// 
	// mToolStriputtonNew
	// 
	this->mToolStriputtonNew->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStriputtonNew->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStriputtonNew.Image")));
	this->mToolStriputtonNew->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStriputtonNew->Name = L"mToolStriputtonNew";
	this->mToolStriputtonNew->Size = System::Drawing::Size(23, 22);
	this->mToolStriputtonNew->Text = L"&New";
	// 
	// mToolStripButtonOpen
	// 
	this->mToolStripButtonOpen->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonOpen->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonOpen.Image")));
	this->mToolStripButtonOpen->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonOpen->Name = L"mToolStripButtonOpen";
	this->mToolStripButtonOpen->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonOpen->Text = L"&Open";
	// 
	// mToolStripButtonSave
	// 
	this->mToolStripButtonSave->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonSave->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonSave.Image")));
	this->mToolStripButtonSave->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonSave->Name = L"mToolStripButtonSave";
	this->mToolStripButtonSave->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonSave->Text = L"&Save";
	// 
	// mToolStripButtonPrint
	// 
	this->mToolStripButtonPrint->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonPrint->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonPrint.Image")));
	this->mToolStripButtonPrint->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonPrint->Name = L"mToolStripButtonPrint";
	this->mToolStripButtonPrint->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonPrint->Text = L"&Print";
	// 
	// mToolStripSeparator
	// 
	this->mToolStripSeparator->Name = L"mToolStripSeparator";
	this->mToolStripSeparator->Size = System::Drawing::Size(6, 25);
	// 
	// mToolStripButtonCut
	// 
	this->mToolStripButtonCut->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonCut->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonCut.Image")));
	this->mToolStripButtonCut->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonCut->Name = L"mToolStripButtonCut";
	this->mToolStripButtonCut->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonCut->Text = L"C&ut";
	// 
	// mToolStripButtonCopy
	// 
	this->mToolStripButtonCopy->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonCopy->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonCopy.Image")));
	this->mToolStripButtonCopy->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonCopy->Name = L"mToolStripButtonCopy";
	this->mToolStripButtonCopy->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonCopy->Text = L"&Copy";
	// 
	// mToolStripButtonPaste
	// 
	this->mToolStripButtonPaste->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonPaste->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonPaste.Image")));
	this->mToolStripButtonPaste->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonPaste->Name = L"mToolStripButtonPaste";
	this->mToolStripButtonPaste->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonPaste->Text = L"&Paste";
	// 
	// mmToolStripFileSeparator2
	// 
	this->mmToolStripFileSeparator2->Name = L"mmToolStripFileSeparator2";
	this->mmToolStripFileSeparator2->Size = System::Drawing::Size(6, 25);
	// 
	// mToolStripButtonHelp
	// 
	this->mToolStripButtonHelp->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
	this->mToolStripButtonHelp->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"mToolStripButtonHelp.Image")));
	this->mToolStripButtonHelp->ImageTransparentColor = System::Drawing::Color::Magenta;
	this->mToolStripButtonHelp->Name = L"mToolStripButtonHelp";
	this->mToolStripButtonHelp->Size = System::Drawing::Size(23, 22);
	this->mToolStripButtonHelp->Text = L"He&lp";
	// 
	// mToolStripContainer
	// 
	// 
	// mToolStripContainer.BottomToolStripPanel
	// 
	this->mToolStripContainer->BottomToolStripPanel->Controls->Add(this->mStatusStrip);
	// 
	// mToolStripContainer.ContentPanel
	// 
	this->mToolStripContainer->ContentPanel->Controls->Add(this->mDockPanel);
	this->mToolStripContainer->ContentPanel->Size = System::Drawing::Size(784, 491);
	this->mToolStripContainer->Dock = System::Windows::Forms::DockStyle::Fill;
	this->mToolStripContainer->Location = System::Drawing::Point(0, 24);
	this->mToolStripContainer->Name = L"mToolStripContainer";
	this->mToolStripContainer->Size = System::Drawing::Size(784, 538);
	this->mToolStripContainer->TabIndex = 3;
	this->mToolStripContainer->Text = L"toolStripContainer1";
	// 
	// mToolStripContainer.TopToolStripPanel
	// 
	this->mToolStripContainer->TopToolStripPanel->Controls->Add(this->mToolStrip);
	// 
	// mStatusStrip
	// 
	this->mStatusStrip->Dock = System::Windows::Forms::DockStyle::None;
	this->mStatusStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->mToolStripStatusLabel});
	this->mStatusStrip->Location = System::Drawing::Point(0, 0);
	this->mStatusStrip->Name = L"mStatusStrip";
	this->mStatusStrip->Size = System::Drawing::Size(784, 22);
	this->mStatusStrip->TabIndex = 1;
	this->mStatusStrip->Text = L"statusStrip1";
	// 
	// mToolStripStatusLabel
	// 
	this->mToolStripStatusLabel->Name = L"mToolStripStatusLabel";
	this->mToolStripStatusLabel->Size = System::Drawing::Size(118, 17);
	this->mToolStripStatusLabel->Text = L"toolStripStatusLabel1";
	// 
	// Mainform
	// 
	this->AllowDrop = true;
	this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
	this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
	this->ClientSize = System::Drawing::Size(784, 562);
	this->Controls->Add(this->mToolStripContainer);
	this->Controls->Add(this->mMenuStrip);
	this->MainMenuStrip = this->mMenuStrip;
	this->Name = L"Mainform";
	this->Text = L"OgreUnified";
	//this->DragEnter += gcnew System::Windows::Forms::DragEventHandler(this, &Mainform::Mainform_DragEnter);
	this->mMenuStrip->ResumeLayout(false);
	this->mMenuStrip->PerformLayout();
	this->mToolStrip->ResumeLayout(false);
	this->mToolStrip->PerformLayout();
	this->mToolStripContainer->BottomToolStripPanel->ResumeLayout(false);
	this->mToolStripContainer->BottomToolStripPanel->PerformLayout();
	this->mToolStripContainer->ContentPanel->ResumeLayout(false);
	this->mToolStripContainer->TopToolStripPanel->ResumeLayout(false);
	this->mToolStripContainer->TopToolStripPanel->PerformLayout();
	this->mToolStripContainer->ResumeLayout(false);
	this->mToolStripContainer->PerformLayout();
	this->mStatusStrip->ResumeLayout(false);
	this->mStatusStrip->PerformLayout();
	this->ResumeLayout(false);
	this->PerformLayout();

}

/*------------------Windows view---------------------------------------------------------------------*/
System::Void Mainform::mToolStripMenuItemSave_Click(System::Object^  sender, System::EventArgs^  e)
{
	mDockPanel->SaveAsXml("Layout.xml");
}

void Mainform::SetStatusBarInfo(System::String^ mes)
{
	mToolStripStatusLabel->Text = mes;
}

void Mainform::CloseAllDocuments()
{
	if (mDockPanel->DocumentStyle == DocumentStyle::SystemMdi)
	{
		for each (Form^ form in MdiChildren)
			form->Close();
	}
	else
	{
		for (int index = mDockPanel->Contents->Count - 1; index >= 0; index--)
		{
			//if (mDockPanel->Contents[index]::typeid ==  IDockContent)
			{
				DockContent^ content = (DockContent^)mDockPanel->Contents[index];
				content->DockPanel=nullptr;//bDockHandler->Close();
			}
		}
	}
}

System::Void Mainform::mToolStripMenuItemLoad_Click(System::Object^  sender, System::EventArgs^  e)
{
	if(!System::IO::File::Exists("Layout.xml"))
	{
		ConsoleForm::Instance->logMessage("No default layout found!");
		return;
	}
	
	// close all SceneViews 
	SceneViewManager::Instance->removeAllSceneView();

	//remove all dockpanel ref from forms
	/*	ConsoleForm::Instance->DockPanel = nullptr;
	HierarchyForm::Instance->DockPanel = nullptr;
	InspectorForm::Instance->DockPanel = nullptr;
	ProjectForm::Instance->DockPanel = nullptr;
	*/
	CloseAllDocuments();

	//now load
	mDockPanel->LoadFromXml("Layout.xml", gcnew WeifenLuo::WinFormsUI::Docking::DeserializeDockContent(this, &Mainform::LoadLayoutCallback ));
}

/*-------------------Windows menu callbacks-------------------------------------------------------*/
System::Void Mainform::mToolStripMenuItemConsole_Click(System::Object^  sender, System::EventArgs^  e)
{
	ConsoleForm::Instance->Show(mDockPanel);
}

System::Void Mainform::mToolStripMenuItemGameView_Click(System::Object^  sender, System::EventArgs^  e)
{
	
}

System::Void Mainform::mToolStripMenuItemSceneView_Click(System::Object^  sender, System::EventArgs^  e)
{
	SceneViewManager::Instance->addSceneView()->Show(mDockPanel);
}

System::Void Mainform::mToolStripMenuItemInspector_Click(System::Object^  sender, System::EventArgs^  e)
{
	InspectorForm::Instance->Show(mDockPanel);
}

System::Void Mainform::mToolStripMenuItemProject_Click(System::Object^  sender, System::EventArgs^  e)
{
	ProjectResourcesForm::Instance->Show(mDockPanel);
}

System::Void Mainform::mToolStripMenuItemHierarchy_Click(System::Object^  sender, System::EventArgs^  e)
{
	HierarchyForm::Instance->Show(mDockPanel);
}

/*-------------------File menu callbacks-------------------------------------------------------*/
System::Void Mainform::mToolStripMenuItemNewScene_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemOpenScene_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemSaveScene_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemSaveSceneAs_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemNewProject_Click(System::Object^  sender, System::EventArgs^  e)
{
	ProjectSetupForm::Instance->ShowDialog(true);
}

System::Void Mainform::mToolStripMenuItemOpenProject_Click(System::Object^  sender, System::EventArgs^  e)
{
	ProjectSetupForm::Instance->ShowDialog();
}

System::Void Mainform::mToolStripMenuItemSaveProject_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemBuildSettings_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemBuildRun_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void Mainform::mToolStripMenuItemExit_Click(System::Object^  sender, System::EventArgs^  e)
{
	Application::Exit();
}
/*--------------------------------------------------------------------------------------------------------------*/

System::Void Mainform::Mainform_DragEnter(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e)
{
	ConsoleForm::Instance->logMessage("dragenter", LOG_TYPE::LOG_WARNING);
}

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Mainform());
	return 0;
}
